<?php

/**
 * ecshop ERP v1.0
 * ----------------------------------------------------------------------------
 * http://www.phpally.com
 * Jacklee的博客 致力于php技术
 * ----------------------------------------------------------------------------
 * 作者: Jacklee
 * 邮箱: jack349392900@gmail.com
 * 创建时间: 2013-11-18
 * 最后修改时间: 2013-11-18
 */

if (!defined('IN_ECS'))
{
    die('Hacking attempt');
}




/**
 * 判断订单是否存在，是否已被删除，存在返回true，否则返回false;
 */

function is_order_exists($order_id='',$order_sn='')
{
	$num=0;
	if(empty($order_id) && empty($order_sn))
	{
		return false;
	}
	elseif(!empty($order_id) && empty($order_sn))
	{
		$sql="select count(*) as num from ".$GLOBALS['ecs']->table('erp_order')." where order_id='".$order_id."'";
		$num=$GLOBALS['db']->getRow($sql);
	}
	elseif(empty($order_id) && !empty($order_sn))
	{
		$sql="select count(*) as num from ".$GLOBALS['ecs']->table('erp_order')." where order_sn ='".$order_sn."'";
		$num=$GLOBALS['db']->getRow($sql);	
	}	
	
	if($num==0)
	{
		return false;
	}
	else{
		return true;
	}
}


/**
 * 返回订单信息
 * @param   
 * $is_deleted 是否已被删除，默认返回未被删除的生产通知单信息
 * $start	开始行号
 * $num		返回行数 limit $start,$num
 */
function get_order_info($order_id='',$order_sn='',$status='',$start_time='',$end_time='',$supplier_id='',$admin_id='',$start=-1,$num=-1)
{
	if(empty($order_id) && empty($order_sn))
	{
		$sql="select * from ".$GLOBALS['ecs']->table('erp_order')." where 1 ";
		
		if(!empty($status))
		{
			$sql.=" and order_status='".$status."'";
		}
		if(!empty($start_time) && empty($end_time))
		{
			$sql.=" and create_time >='".$start_time."'";
		}
		elseif(empty($start_time) && !empty($end_time))
		{
			$sql.=" and create_time <='".$end_time."'";
		}	
		elseif(!empty($start_time) && !empty($end_time))
		{
			$sql.=" and create_time >='".$start_time."' and create_time <='".$end_time."'";
		}	
		
		if(!empty($supplier_id))
		{
			$sql.=" and supplier_id='".$supplier_id."'";
		}

		if(!empty($admin_id))
		{
			$sql.=" and create_by ='".$admin_id."'";
		}
		
		$sql.=" order by order_sn desc ";
		
		if($start!=-1 && $num!=-1)
		{
			if($start<=0)
			{
				$start=0;
				}
			$sql.=" limit ".$start.",".$num;
			
		}
	}
	elseif(!empty($order_id) && empty($order_sn))
	{
		if(is_order_exists($order_id))
		{
			$sql="select * from ".$GLOBALS['ecs']->table('erp_order')." where order_id=".$order_id."";		
		}
		else{
			return false;
		}
	}
	elseif(empty($order_id) && !empty($order_sn))
	{
		if(is_order_exists('',$order_sn))
		{
			$sql="select * from ".$GLOBALS['ecs']->table('erp_order')." where order_sn='".$order_sn."'";	
		}
		else{
			return false;
		}
		
	}
	
	$order_info=$GLOBALS['db']->getAll($sql);
	
	if(!empty($order_info))
	{
		foreach($order_info as $key	=> $item)
		{
			$order_id=$item['order_id'];
			$order_info[$key]['available_act']=get_order_available_act($order_id,'');		
			
			$supplier_id=$item['supplier_id'];
			$sql="select name,code from ".$GLOBALS['ecs']->table('erp_supplier')." where supplier_id='".$supplier_id."'";
			$supplier_info=$GLOBALS['db']->getRow($sql);
			
			$order_info[$key]['supplier_name']=$supplier_info['name'];
			$order_info[$key]['supplier_code']=$supplier_info['code'];	
			
		  //订单总数和总金额
			$order_summary=get_order_summary($order_id);
			$order_info[$key]['order_qty']=$order_summary['order_qty'];
			$order_info[$key]['order_amount']=$order_summary['order_amount'];					
			
			//重新格式化时间
			$order_info[$key]['create_date']=date('Y-m-d',$item['create_time']);	
			$order_info[$key]['post_date']=date('Y-m-d',$item['post_time']);	
			$order_info[$key]['rated_date']=date('Y-m-d',$item['rated_time']);
			$order_info[$key]['approve_date']=date('Y-m-d',$item['approve_time']);	
			$order_info[$key]['execute_date']=date('Y-m-d',$item['execute_time']);
			$order_info[$key]['finish_date']=date('Y-m-d',$item['finish_time']);			
		}
	}
	
	return $order_info;
}


/**
 * 返回订单项信息
 */
function get_order_item_info($order_id='')
{
	if(empty($order_id))
	{
		return array();
	}
	else
	{
		$order_item_info=array();

		$sql="select * from ".$GLOBALS['ecs']->table('erp_order_item')." where order_id='".$order_id."' order by order_item_id desc";
		$order_items=$GLOBALS['db']->getAll($sql);
	
		if(!empty($order_items))
		{
			foreach($order_items as $key => $item)
			{
				//获取产品信息
				$goods_id=$item['goods_id'];
				
				$sql="select cat_id,goods_id,goods_sn,goods_name,goods_thumb,goods_img from ";
				$sql.=$GLOBALS['ecs']->table('goods')." where goods_id='".$goods_id."'";
				$goods_details=$GLOBALS['db']->getRow($sql);
				//处理产品图片
				if(!empty($goods_details['goods_thumb']))
				{
					$goods_details['goods_thumb']='../'.$goods_details['goods_thumb'];
				}
				if(!empty($goods_details['goods_img']))
				{
					$goods_details['goods_img']='../'.$goods_details['goods_img'];
				}
				
				$order_items[$key]['goods_details']=$goods_details;
	
				
				$order_items[$key]['goods_attr']=get_goods_attr($item['goods_id']);
				
				$attr_info=get_attr_info($item['attr_id']);
				
				$order_items[$key]['selected_attr']=$attr_info['attr_info'];
					
			}
			return $order_items;
		}
		else{
			return array();
		}
	}
}

function delete_order_item($oder_id='',$order_item_id='')
{
	if(!empty($oder_id) && empty($order_item_id))
	{
		$sql="delete from ".$GLOBALS['ecs']->table('erp_order_item')." where order_id='".$oder_id."'";
	}
	elseif(empty($oder_id) && !empty($order_item_id))
	{
		$sql="delete from ".$GLOBALS['ecs']->table('erp_order_item')." where order_item_id='".$order_item_id."'";
	}
	else{
		return false;
	}
	
	$GLOBALS['db']->query($sql);
	return true;		
}


/**
 * 返回订单项定购总数和总金额
 */

function get_order_summary($order_id='')
{
	if(empty($order_id))
	{
		return false;
	}
	else{
			$sql="select sum(order_qty) as order_qty, sum(amount) as order_amount from ".$GLOBALS['ecs']->table('erp_order_item')." where order_id='".$order_id."' group by order_id";
			return $GLOBALS['db']->getRow($sql);		
	}
}


/**
 * 检查订单是否完善，检查的内容有：
 * 1，是否选择了供应商
 * 2，是否最少含一条订单项
 * 3，是否所有订单项都选择了产品
 * 4，有属性的是否都选了属性
 * 5，每项是否都输入了定购数量
 */

function check_order_integrity($order_id='')
{
	if(empty($order_id))
	{
		return false;
	}
	$order_info=get_order_info($order_id);
	$order_item_info=get_order_item_info($order_id);
	
	$supplier_id=$order_info[0]['supplier_id'];
	if(empty($supplier_id))
	{
		return 1;
	}
	
	if(empty($order_item_info))
	{
		return 2;
	}
	
	foreach($order_item_info as $order_item)
	{
		$goods_id=$order_item['goods_id'];
		if(empty($goods_id))
		{
			return 3;
		}
		else{
			$goods_attr=get_goods_attr($goods_id);
			if(!empty($goods_attr) && empty($order_item['selected_attr']))
			{
				return 4;
			}
			
			if(empty($order_item['order_qty']))
			{
				return 5;
			}
		}
	}
	return true;
}




function add_order()
{	
	$user_id=erp_get_admin_id();
	$order_sn=gen_order_sn();
	
	$sql="insert into ".$GLOBALS['ecs']->table('erp_order')." set ";
	$sql.="order_sn='".$order_sn."',";
	$sql.="create_time='".time()."',";
	$sql.="create_by='".$user_id."',";
	$sql.="is_locked ='0',";
	$sql.="order_status ='1'";

	
	if($GLOBALS['db']->query($sql))
	{
			$sql="select order_id from ".$GLOBALS['ecs']->table('erp_order')." where order_sn='".$order_sn."'";
			$order_id=$GLOBALS['db']->getOne($sql);
			return $order_id;
	}
	else{
			return false;
	}		
}



function post_order($order_id='')
{
	if(is_order_exists($order_id))
	{
		$sql="update ".$GLOBALS['ecs']->table('erp_order')." set order_status='2' where order_id='".$order_id."'";
		
		if($GLOBALS['db']->query($sql))
		{
			return true;
		}
		else{
			return false;
		}	

	}
	else{
		return false;
	}	
}


/**
 * 订单是否最少有一个定单项
 */
function has_order_item($order_id='')
{
	if(empty($order_id))
	{
		return false;
	}
	else{
		$sql="select order_item_id from ".$GLOBALS['ecs']->table('erp_order_item')." where order_id='".$order_id."'";
		$res=$GLOBALS['db']->query($sql);
		while(list($order_item_id)=mysql_fetch_row($res))
		{
			$order_item_id_array[]=$order_item_id;
		}
		if(empty($order_item_id_array))
		{
			return false;
		}
		else{
			return $order_item_id_array;
		}
	}
}


/**
 * 记录修改订单的用户和时间
 * $act=create,modify,post,rate,submit,approve,delete
 */

function order_act_record($order_id='',$act='')
{
	if(empty($order_id))
	{
		return false;
	}
	if(!is_order_exists($order_id))
	{
		return false;
	}
	if(empty($act))
	{
		return false;
	}
	
	$user_id=erp_get_admin_id();
	$current_time=time();	
	
	if($act=='create')
	{
		$sql="update ".$GLOBALS['ecs']->table('erp_order')." set create_by='".$user_id."'";
		$sql.=", create_time='".$current_time."' where order_id='".$order_id."'";
	}
	elseif($act=='post')
	{
		$sql="update ".$GLOBALS['ecs']->table('erp_order')." set post_by='".$user_id."'";
		$sql.=", post_time='".$current_time."' where order_id='".$order_id."'";
	}
	elseif($act=='rate')
	{
		$sql="update ".$GLOBALS['ecs']->table('erp_order')." set rate_by ='".$user_id."'";
		$sql.=", rate_time='".$current_time."' where order_id='".$order_id."'";
	}	
	elseif($act=='approve')
	{
		$sql="update ".$GLOBALS['ecs']->table('erp_order')." set approve_by ='".$user_id."'";
		$sql.=", approve_time='".$current_time."' where order_id='".$order_id."'";
	}		
	elseif($act=='submit')
	{
		$sql="update ".$GLOBALS['ecs']->table('erp_order')." set submit_by  ='".$user_id."'";
		$sql.=", submit_time ='".$current_time."' where order_id='".$order_id."'";
	}				

	$GLOBALS['db']->query($sql);
		
	return true;
}

/**
 * 删除订单
 */
function delete_order($order_id='')
{
	if(empty($order_id))
	{
		return false;
	}

	$sql="delete from ".$GLOBALS['ecs']->table('erp_order')." where order_id='".$order_id."'";
	$GLOBALS['db']->query($sql);	
	return true;	
}



/**
 * 判断订单项是否存在，是否已被删除，存在返回true，否则返回false;
 */

function is_order_item_exists($order_item_id='')
{
	if(empty($order_item_id))
	{
		return false;
	}
	else
	{
		$sql="select count(*) as num from ".$GLOBALS['ecs']->table('erp_order_item')." where order_item_id ='".$order_item_id."'";
		$num=$GLOBALS['db']->getOne($sql);
		
		if($num==0)
		{
			return false;
		}
		else
		{
			return true;
		}		
	}	
}




/**
 * 锁定订单，以排斥的访问该订单
 * 成功，返回true,失败返回false.
 */

$expired_time=3600;

function lock_order($order_id='',$act='')
{
	if(empty($order_id))
	{
		return false;
	}
	
	if(check_accessibility($order_id,$act))
	{	
	
		$user_id=erp_get_admin_id();
		
		$lock_time=time();
		$last_act_time=time();
	
		$sql="update ".$GLOBALS['ecs']->table('erp_order')." set locked_by='".$user_id."'";
		$sql.=", locked_time='".$lock_time."'";
		$sql.=", last_act_time='".$last_act_time."'";
		$sql.=", is_locked='1'";
		$sql.=" where order_id='".$order_id."'";
	
		$GLOBALS['db']->query($sql);
	
		return true;
	}
	else{
		return false;
	}
}


/**
 * 访问订单，更新操作时间，以排斥地访问该订单
 * 如果该订单有其他客户在访问，返回false
 * $act=view,edit,delete,post_to_rate,rate,post_to_approve,approve.
 */
function access_order($order_id='',$act='')
{
	if(empty($order_id))
	{
		return false;
	}
	
	if(check_accessibility($order_id,$act))
	{
		$user_id=!empty($_COOKIE['ECSCP']['admin_id'])?$_COOKIE['ECSCP']['admin_id']:'';
		$user_id=isset($_SESSION['admin_id'])?$_SESSION['admin_id']:'';
	
		$lock_time=time();
		$last_act_time=time();
	
		$sql="update ".$GLOBALS['ecs']->table('erp_order')." set last_act_time='".$last_act_time."'";
		$sql.=" where order_id='".$order_id."'";
	
		$GLOBALS['db']->query($sql);
	
		return true;
	}
	else{
		return false;
	}
}


/**
 * 核对但前时间用户对某个订单是否能进行某项操作。Return true or false;
 * $act=view,edit,delete,post_to_rate,rate,post_to_approve,approve.
 */

function check_accessibility($order_id='',$act='')
{
	if(empty($act) && empty($order_id))
	{
		return false;
	}
	else
	{
		$sql="select is_locked,order_status,last_act_time,locked_by from ".$GLOBALS['ecs']->table('erp_order')." where order_id='".$order_id."'";
		$res=$GLOBALS['db']->getRow($sql);
		if($res==false)
		{
			return false;
		}
		else{
			
		$is_locked=$res['is_locked'];
		$order_status=$res['order_status'];
		$last_act_time=$res['last_act_time'];//最后的订单操作的时间，如果用户在一个小时内无任何操作的时候，自动解除订单锁定。
		$locked_by=$res['locked_by'];	
		
		$current_time=time();
		$if_overtime=(($current_time-$last_act_time)>(10))? 1:0;//大于一个小时，表示操作超时。
	
		$current_user_id=erp_get_admin_id();
		
		if($act=='view')
		{
			return(admin_priv('erp_order_view', '', false));
		}
		elseif($act=='edit' || $act=='delete' || $act=='post_to_rate')
		{
			if($order_status==1)
			{
				if(admin_priv('erp_order_manage', '', false) && ($is_locked==0 || ($is_locked==1 && $if_overtime==1 && $current_user_id!=$locked_by) || ($is_locked==1 && $current_user_id==$locked_by)))
				{
					return true;
				}
				else{
					return false;
				}
			}
			else{
				return false;
			}	
		}
		elseif($act=='rate' || $act=='post_to_approve')
		{
			if($order_status==2)
			{
				if(admin_priv('erp_order_rate', '', false) && ($is_locked==0 || ($is_locked==1 && $if_overtime==1 && $current_user_id!=$locked_by) || ($is_locked==1 && $current_user_id==$locked_by)))
				{
					return true;
				}
				else{
					return false;
				}				
			}
			else{
				return false;
			}
		}
		elseif($act=='approve')
		{
			if($order_status==3)
			{
				if(admin_priv('erp_order_approve', '', false) && ($is_locked==0 || ($is_locked==1 && $if_overtime==1 && $current_user_id!=$locked_by) || ($is_locked==1 && $current_user_id==$locked_by)))
				{
					return true;
				}
				else{
					return false;
				}				
			}
			else{
				return false;
			}
		}
		else{
			return false;
		}
		}
	}
}



/**
 * 产生生产通知单号（订单号，生产通知单号是形如'PO0911021'的9位字符串
 * 其中PO表示Purchase Order,09表示2009年，11表示11月份，最后的三位是序号。0911021，表示09年11月的第21个生产通知单。
 */

function gen_order_sn()
{
	$sql="select order_sn from ".$GLOBALS['ecs']->table('erp_order')." order by order_sn desc limit 1";
	$result=$GLOBALS['db']->getOne($sql);
	
	if(!empty($result))
	{
		$year_date=substr($result,2,4);
		$current_year_date=date("ym");
		if($current_year_date==$year_date)
		{
			$sn=substr($result,6,3);//获取后三位的序号
			$sn=intval($sn)+1;	//序号加1
			$sn=gen_zero_str(3-strlen($sn)).$sn;//加前导'0'
			$sn='PO'.$year_date.$sn;//加年，月
			
			return $sn;
		}
		else
		{
			$sn='PO'.$current_year_date."001";
			return $sn;
		}	
	}
	else{
		$current_year_date=date("ym");
		$sn='PO'.$current_year_date."001";
		return $sn;
	}
}


/**
 * 返回订单的有效操作
 */

function get_order_available_act($order_id='',$order_sn='')
{
	/*	order_status=1  	表示正录入
	 * 	order_status=2  	财务处理中
	 *	order_status=3  	审核中
	 *  order_status=4  	审核通过
	 *  order_status=5  	审核不通过
	 *  order_status=6  	执行
	 *  order_status=7  	完结
	*/
	
	$sql='';
	$act=array('view'=>0, 'edit'=>0, 'delete'=>0, 'post_to_rate'=>0, 'rate'=>0, 'post_to_approve'=>0, 'approve'=>0);
	$is_locked='';
	$order_status='';
	
	if(empty($order_id) && empty($order_sn))
	{
		return false;
	}
	if(empty($order_sn) && !empty($order_id))
	{
		$sql="select is_locked,order_status,last_act_time,locked_by from ".$GLOBALS['ecs']->table('erp_order')." where order_id='".$order_id."'";
	}
	elseif(!empty($order_sn) && empty($order_id))
	{
		$sql="select is_locked,order_status,last_act_time,locked_by from ".$GLOBALS['ecs']->table('erp_order')." where order_sn='".$order_sn."'";
	}
	$res=$GLOBALS['db']->getRow($sql);
	
	if($res===false)
	{
		return false;
	}
	else{
		$is_locked=$res['is_locked'];
		$order_status=$res['order_status'];
		$last_act_time=$res['last_act_time'];//最后的订单操作的时间，如果用户在一个小时内无任何操作的时候，自动解除订单锁定。
		$locked_by=$res['locked_by'];
	}

	$current_time=time();
	$if_overtime=(($current_time-$last_act_time)>(10))? 1:0;//大于一个小时，表示操作超时。
	
	$current_user_id=!empty($_COOKIE['ECSCP']['admin_id'])? $_COOKIE['ECSCP']['admin_id']:'';
	$current_user_id=isset($_SESSION['admin_id'])?$_SESSION['admin_id']:$current_user_id;
	
	//Todo:如果用户在订单编辑状态，但是1个小时内没有操作，也没有退出，这个时候其他用户进入编辑，然而这个客户又进行操作。。。	

	if($order_status==1)
	{
			if(admin_priv('erp_order_view', '', false) || admin_priv('erp_order_manage', '', false) || admin_priv('erp_order_rate', '', false) || admin_priv('erp_order_approve', '', false))
			{
				$act['view']=1;
			}
			else{
				$act['view']=0;
			}
			
			if(admin_priv('erp_order_manage', '', false) && ($is_locked==0 || ($is_locked==1 && $if_overtime==1 && $current_user_id!=$locked_by) || ($is_locked==1 && $current_user_id==$locked_by)))
			{
				$act['edit']=1;
				$act['delete']=1;
				$act['post_to_rate']=1;
			}
			else{
				$act['edit']=0;
				$act['delete']=0;
				$act['post_to_rate']=0;
			}
			
			$act['rate']=0;
			$act['post_to_approve']=0;
			
			$act['approve']=0;
			$act['execute']=0;
			$act['finish']=0;
			
			return $act;
	}
	elseif($order_status==2)
	{
			if(admin_priv('erp_order_view', '', false) || admin_priv('erp_order_manage', '', false) || admin_priv('erp_order_rate', '', false) || admin_priv('erp_order_approve', '', false))
			{
				$act['view']=1;
			}
			else{
				$act['view']=0;
			}

			$act['edit']=0;
			$act['delete']=0;
			$act['post_to_rate']=0;
			
			if(admin_priv('erp_order_rate', '', false) && ($is_locked==0 || ($is_locked==1 && $if_overtime==1 && $current_user_id!=$locked_by) || ($is_locked==1 &&  $current_user_id==$locked_by)))
			{
				$act['rate']=1;
				$act['post_to_approve']=1;
			}
			else
			{
				$act['rate']=0;
				$act['post_to_approve']=0;				
			}
			
			$act['approve']=0;
			$act['execute']=0;
			$act['finish']=0;
			return $act;
	}
	elseif($order_status==3)
	{
			if(admin_priv('erp_order_view', '', false) || admin_priv('erp_order_manage', '', false) || admin_priv('erp_order_rate', '', false) || admin_priv('erp_order_approve', '', false))
			{
				$act['view']=1;
			}
			else{
				$act['view']=0;
			}
			
			$act['edit']=0;
			$act['delete']=0;
			$act['post_to_rate']=0;
			$act['rate']=0;
			$act['post_to_approve']=0;				

			$act['approve']=admin_priv('erp_order_approve', '', false)? 1:0;	
			$act['execute']=0;
			$act['finish']=0;
			return $act;
	}
	elseif($order_status==4 || $order_status==5)
	{
			$act['view']=0;
			$act['edit']=0;
			$act['delete']=0;
			$act['post_to_rate']=0;
			$act['rate']=0;
			$act['post_to_approve']=0;				

			$act['approve']=0;
			if($order_status==4) {
				$act['execute']=1;
				$act['finish']=0;
			} else {
				$act['execute']=0;
				$act['finish']=0;
			}
			return $act;
	}
	elseif($order_status==6)
	{
			$act['view']=0;
			$act['edit']=0;
			$act['delete']=0;
			$act['post_to_rate']=0;
			$act['rate']=0;
			$act['post_to_approve']=0;				

			$act['approve']=0;
			$act['execute']=0;
			$act['finish']=1;
			return $act;
	}
	else
	{
			return false;
		}
}


function get_order_status()
{
	
	$order_status[0]['status_no']=1;
	$order_status[0]['status_style']="订单录入中";

	$order_status[1]['status_no']=2;
	$order_status[1]['status_style']="财务处理中";
	
	$order_status[2]['status_no']=3;
	$order_status[2]['status_style']="主管审核中";

	$order_status[3]['status_no']=4;
	$order_status[3]['status_style']="审核已通过";

	$order_status[4]['status_no']=5;
	$order_status[4]['status_style']="审核未通过";
	
	$order_status[5]['status_no']=6;
	$order_status[5]['status_style']="已执行";
	
	$order_status[6]['status_no']=7;
	$order_status[6]['status_style']="已结算";
	
	return $order_status;	
}


/**
 * 确定成品供应商编号是否已存在，存在返回true.
 * @param  
 * $supplier_id 成品供应商序号
 * $code 成品供应商编号
 */

function is_supplier_code_exist($supplier_id=0,$code='')
{
	$sql="select * from ".$GLOBALS['ecs']->table('erp_supplier')." where code='".$code."' and supplier_id<>'".$supplier_id."'";
	$result=$GLOBALS['db']->getRow($sql);
	if($result==false)
	{
		return false;
		}
	else
	{
		return true;
		}
}


/**
 * 格式化布板,样板图图片名称（按目录存储）
 *$sn 布板或样板图的编号
 *$sub_dir stuff_img或draft_img
 *$position source_img或thumb_img
 *$source_img 原图片地址
 */
function reformat_image_name($sn, $sub_dir,$source_img)
{
    $img_ext = substr($source_img, strrpos($source_img, '.'));//扩展名
    $dir = 'images';

	if (!make_dir(ROOT_PATH.$dir.'/'.$sub_dir))
    {
        return false;
    }
		
	$img_name = $sn.$img_ext;

    if (move_image_file(ROOT_PATH.$source_img, ROOT_PATH.$dir.'/'.$sub_dir.'/'.$img_name))
	{
           return '../'.$dir.'/'.$sub_dir.'/'.$img_name;
        }

    return false;
}

function move_image_file($source, $dest)
{
    if (@copy($source, $dest))
    {
        @unlink($source);
        return true;
    }
    return false;
}

?>